package com.jty.lib_base.room.dao

import androidx.room.*
import com.jty.lib_base.room.bean.NoteItem


/**
 * author: zhouyh
 * created on: 2022/3/22 9:19 上午
 * description: 教研笔记数据库
 */
@Dao
interface NoteItemDao {

    @Query("SELECT * FROM notes")
    fun getAll(): List<NoteItem>

    @Query("SELECT * FROM notes WHERE id IN (:ids)")
    fun loadAllByIds(ids: IntArray): List<NoteItem>

    @Query("SELECT * FROM notes WHERE id = (:id) LIMIT 1")
    fun queryById(id: Long): NoteItem?

    @Query("SELECT * FROM notes WHERE note_id = (:noteId) LIMIT 1")
    fun queryByNoteId(noteId: String): NoteItem?


    @Query("SELECT * FROM notes WHERE note_id = (:serverPath) LIMIT 1")
    fun queryByServerPath(serverPath: String): NoteItem?



    @Insert
    fun insertAll(vararg noteItem: NoteItem)

    @Insert(onConflict = OnConflictStrategy.REPLACE) //如果有相同的id就替换； ABORT默认这个，如果相同，会报错
    fun insertNoteItem(vararg noteItem: NoteItem)

    @Query("Delete from notes WHERE note_id = (:noteId)")
    fun deleteByNoteId(noteId: String)

    @Query("Delete from notes WHERE pageserial = (:pageserial)")
    fun deleteByNotePageserial(pageserial: String)

    @Delete
    fun delete(noteItem: NoteItem)

    @Delete
    fun deleteAll(vararg noteItem: NoteItem)

    @Update
    fun updateNoteItems(vararg noteItem: NoteItem)


    @Query("SELECT * FROM notes WHERE research_id = (:researchId) AND way = (:way)")
    fun getNoteItems(researchId:String,way:Int):List<NoteItem>

    @Query("SELECT * FROM notes WHERE research_id = (:researchId)")
    fun getNoteItemsById(researchId:String):List<NoteItem>

    @Query("SELECT * FROM notes WHERE local_path = (:local_path) And research_id=(:researchId)")
    fun getNoteItemByLocalPathAndId(local_path:String,researchId: String):NoteItem



    @Query("Delete from notes WHERE research_id = (:researchId)")
    fun deleteNoteByResearchId(researchId:String)

    @Query("Delete from notes WHERE research_id = (:researchId) And way =(:way)")
    fun deleteNoteByIdAndWay(researchId:String,way: Int)




}